﻿using System;
using System.Runtime.CompilerServices;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.Common;
using Ths.Components.Common;
using Ths.Framework;
using Ths.Components.Dictionary;
using Ths.Components.Dictionary.Entity;
using Ths.Components.Excel;
using Ths.Components;
using System.Configuration;
using System.Web.Security;
using System.Data.OleDb;
using qiupeng.Public;
using System.IO;
using SafetyRecordData.Data.DAL;

public partial class DistressManage_NotHurtDetailCount : Base
{
    Db List = new Db();
    public static string CountsLabel, AllPageLabel, CurrentlyPageLabel, SqlStrStart, SqlStrMid, SqlStr, SqlStrStartCount, SqlStrCount;
    DANotHurtDistress dal = new DANotHurtDistress();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.Session["username"] == null)
        {
            this.Response.Write("<script language=javascript>alert('登陆超时！');window.parent.location = '../main_d.aspx'</script>");
            return;

        }

        if (!Page.IsPostBack)
        {
            if (GetRequestStr("starttime1") != "")
            {
                this.txtStartTime.Value = GetRequestStr("starttime1");
            }
            if (GetRequestStr("endtime1") != "")
            {
                this.txtEndTime.Value = GetRequestStr("endtime1");
            }
            DataBindToGridview("order by id asc");


        }
    }

    #region 初始化


    #endregion

    //用于构造DbParameter数组
    List<DbParameter> parameterList = new List<DbParameter>();

    public void DataBindToGridview(string Sqlsort)
    {
        this.GridView1.PageSize = 100;
        DbParameter theSqlParameter = null;
        theSqlParameter = dal.DBFactory.CreateParameter("@StartTime", "" + Convert.ToString(txtStartTime.Value.Trim()) + "");
        parameterList.Add(theSqlParameter);
        theSqlParameter = dal.DBFactory.CreateParameter("@EndTime", "" + Convert.ToString(this.txtEndTime.Value) + "");
        parameterList.Add(theSqlParameter);

        string bumenID = "";
        if (Request.QueryString["BuMenID"] != null)
        {
            bumenID = Request.QueryString["BuMenID"].ToString();
        }
        else
        {
            bumenID = Session["BuMenID"].ToString();
        }
        theSqlParameter = dal.DBFactory.CreateParameter("@bumenid", "" + bumenID + "");
        parameterList.Add(theSqlParameter);
        theSqlParameter = dal.DBFactory.CreateParameter("@IsAll", chkAll.Checked ? "1" : "0");
        parameterList.Add(theSqlParameter);
        string isAll = chkAll.Checked ? "1" : "0";
        string where = "'" + bumenID + "','" + txtStartTime.Value.Trim() + "','" + this.txtEndTime.Value + "','" + isAll + "'";
        DataTable dt = dal.GetHurtListDetailCount(parameterList.ToArray(), "", where);
        GridView1.DataSource = dt;
        GridView1.DataBind();



    }







    #region GridView基本信息
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        DataControlRowType itemType = e.Row.RowType;
        if (e.Row.RowType != DataControlRowType.Header)
        {
            e.Row.Attributes["onmouseover"] = "javascript:setMouseOverColor(this);";
            e.Row.Attributes["onmouseout"] = "javascript:setMouseOutColor(this);";

            Label labVisible = (Label)e.Row.FindControl("LabVisible");
            Label lblCount = (Label)e.Row.FindControl("lblAllCount");
            if (lblCount != null && labVisible != null)
            {
                if (labVisible.Text.Trim() == "") { labVisible.Text = "999"; }
                lblCount.Text = "<a href='#' onclick=\"openunit('" + labVisible.Text.Trim() + "','" + Request.QueryString["bumenid"].ToString() + "','" + this.txtStartTime.Value + "','" + this.txtEndTime.Value + "')\">" + lblCount.Text + "</a>";
            }

        }
    }

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        string sql = "";

        if (ViewState["SortDirection"] == null || ViewState["SortDirection"].ToString().CompareTo("") == 0)
        {
            ViewState["SortDirection"] = " desc";
        }
        else
            ViewState["SortDirection"] = "";

        sql = " order by " + e.SortExpression + ViewState["SortDirection"];


        DataBindToGridview(sql);
    }


    #endregion


    protected void btnSave_Click(object sender, EventArgs e)
    {
        this.DataBindToGridview("");
    }
}
